Relax BufferVec's type constraints #12866
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Objective
Since BufferVec was first introduced,
bytemuck
has added additional traits with fewer restrictions thanPod
. Within BufferVec, we only rely on the constraints ofbytemuck::cast_slice
to au8
slice, which now only requiresT: NoUninit
which is a strict superset ofPod
types.Solution
Change out the
Pod
generic type constraint withNoUninit
. Also taking the opportunity to substitutecast_slice
withmust_cast_slice
, which avoids a runtime panic in place of a compile time failure ifT
cannot be used.Changelog
Changed:
BufferVec
now supports working with types containingNoUninit
but notPod
members.Changed:
BufferVec
will now fail to compile if used with a type that cannot be safely read from. Most notably, this includes ZSTs, which would previously always panic at runtime.